package com.itlong.cloud.POJO.VO;

import com.itlong.cloud.enumerate.ecode.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * <desc>
 *      泛型版本 函数返回值对象，其非泛型版本为 Result
 * </desc>
 *
 * @createDate 2017-11-08.
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class TResult<T> extends Result {
    private T data; //业务数据
    private Integer msgCode = 0;
    private String msg;
    private ErrorCode errorCode;

    public TResult(boolean success, String error, T data){
        this.success = success;
        this.error = error;
        this.data = data;
    }

    public TResult(T data){
        this(true, "", data);
    }

    public TResult(boolean success, String error){
        this(success, error, null);
    }



    /** 自定义错误码响应结果
     * @param errorCode
     * @param errorCode
     */
    public TResult(ErrorCode errorCode){
        super();
        this.errorCode=errorCode;
        this.msgCode=errorCode.getSubCode();
        if (this.msgCode != 0){
            this.success = false;
            this.error = errorCode.getCodeMsg();
        }
    }



}
